import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:lib_core/bridge/common_bridge_impl.dart';
import 'package:lib_core/lib_core.dart';
import 'package:lib_core/routes/boost_dialog_route.dart';
import 'package:lib_ui/common/button_action.dart';
import 'package:lib_ui/lib_ui.dart';
import 'package:lib_ui/routes/ui_routes.dart';
import 'package:lib_ui/widget/common_tips_widget.dart';
import 'package:lib_ui/widget/dialog/msg_dialog.dart';

class UiPages {
  UiPages._();

  static final Map<String, FlutterBoostRouteFactory> uiPages = {
    UiRoutes.msgDialog: ((setting, uniqueId) {
      final arguments = setting.arguments as Map<String, dynamic>?;
      final title = arguments?['title'] ?? '标题为空';
      final content = arguments?['content'] ?? '内容为空';
      bool useSafeArea = arguments?['useSafeArea'] ?? true;
      return BoostDialogRoute(
        barrierColor: Colors.black.withOpacity(0.25),
        settings: setting,
        pageBuilder: (context, animation, secondaryAnimation) {
          final pageChild = MsgDialog(
            title: Text(title, style: LDFont.bold()),
            content: Text(content, style: LDFont.regular()),
            negative: ButtonAction(onClick: () {
              BoostNavigator.instance.pop({'confirm': false});
            }),
            positive: ButtonAction(onClick: () {
              BoostNavigator.instance.pop({'confirm': true});
            }),
          );
          Widget dialog = Builder(builder: (context) {
            return Theme(data: Theme.of(context), child: pageChild);
          });
          if (useSafeArea) {
            dialog = SafeArea(child: dialog);
          }
          return dialog;
        },
      );
    }),
    UiRoutes.inputDialog: ((setting, uniqueId) {
      final arguments = setting.arguments as Map<String, dynamic>?;
      final title = arguments?['title'] ?? '标题为空';
      final content = arguments?['content'] ?? '内容为空';
      final hint = arguments?['hint'] ?? '内容为空';
      bool useSafeArea = arguments?['useSafeArea'] ?? true;
      return BoostDialogRoute(
        barrierColor: Colors.black.withOpacity(0.25),
        settings: setting,
        pageBuilder: (context, animation, secondaryAnimation) {
          String text = '';
          final pageChild = MsgDialog(
            title: Text(title, style: LDFont.bold()),
            content: SizedBox(
                height: 50,
                child: CommonTextField(text: content, hint: hint, onTextChanged: (str) => text = str)),
            negative: ButtonAction(onClick: () {
              BoostNavigator.instance.pop({'string': ''});
            }),
            positive: ButtonAction(onClick: () {
              BoostNavigator.instance.pop({'string': text});
            }),
          );
          Widget dialog = Builder(builder: (context) {
            return Theme(data: Theme.of(context), child: pageChild);
          });
          if (useSafeArea) {
            dialog = SafeArea(child: dialog);
          }
          return dialog;
        },
      );
    }),
  };
}
